/*
*	ID : pallab81
* 	PROG : 12040_0
* 	LANG : C++
* 	2012-09-10-17.20.34 Monday
*
* 	"I have not failed, I have just found 10000 ways that won't work.
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;


#define foR(i1,st,ed) for(int i1 = st , j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i1,ed) foR( i1 , 0 , ed )
#define foE(i1,st,ed) foR( i1, st, ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

template<class T1>
inline void debug(T1 _x) {
    cout<<_x<<'\n';
}
template<class T1, class T2>
inline void debug(T1 _x,T2 _y) {
    cout<<_x<<' '<<_y<<'\n';
}
template<class T1, class T2, class T3>
inline void debug(T1 _x,T2 _y,T3 _z) {
    cout<<_x<<' '<<_y<<' '<<_z<<'\n';
}
template<class T1, class T2, class T3, class T4>
inline void debug(T1 _x,T2 _y,T3 _z,T4 _zz) {
    cout<<_x<<' '<<_y<<' '<<_z<<' '<<_zz<<'\n';
}
template< class T1>
inline void debug(T1 _array,int _size) {
    cout<<"[";
    for (int i=0; i<_size; ++i) {
        cout<<' '<<_array[i];
    }
    puts(" ]");
}
inline bool CI(int &_x) {
    return scanf("%d",&_x)==1;
}
inline bool CI(int &_x, int &_y) {
    return CI(_x)&&CI(_y) ;
}
inline bool CI(int &_x, int &_y, int &_z) {
    return CI(_x)&&CI(_y)&&CI(_z) ;
}
inline bool CI(int &_x, int &_y, int &_z, int &_zz) {
    return CI(_x)&&CI(_y)&&CI(_z)&&CI(_zz) ;
}
inline void wait( double seconds ) {
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ) {
        ;
    }
}
#if !defined( ONLINE_JUDGE )
#define debug
#endif

const int max_len = 200;
int N;
char str[max_len];
int l_str;
inline void read() {
    scanf("%d %s",&N,str);
    l_str = strlen(str);
}
int pi[max_len];
inline void prefix_function(char *s) {
    int n = strlen(s);
    SET(pi,0);
    for(int i=1; i<n; ++i) {
        int j=pi[i-1];
        while(j>0&&s[i]!=s[j]) {
            j=pi[j-1];
        }
        if(s[i]==s[j])++j;
        pi[i]=j;
    }
}
int aut[max_len][12];
char s[max_len];
inline void kmp_autometa(char *ss) {
    SET(aut,0);
    sprintf(s,"%s:",ss);
    prefix_function(s);
    int n=strlen(s);
    for(int i=0; i<n; ++i) {
        for(char c='0'; c<=':'; ++c) {
            if(i>0&&c!=s[i]) {
                aut[i][c-'0']=aut[ pi[i-1] ][c-'0'];
            } else {
                aut[i][c-'0']=i+(c==s[i]);
            }
        }
    }
}

bool vis[max_len][max_len];
int dp[max_len][max_len];
const int mod = 10000007;
inline int do_mod(int var) {
    if(var<0)var+=mod;
    return var%mod;
}
int go(int at, int prefix) {
    if( prefix==l_str )return 0;
    if(at==N) {
        return 1;
    }
    if( vis[at][prefix] )return dp[at][prefix];
    vis[at][prefix]=true;
    int nways=0;
    for(int i=(at==0&&N!=1?1:0); i<=9; ++i) {
        int var = go(at+1, aut[prefix][ i ]);
        nways= do_mod(nways+var);
    }
    return dp[at][prefix]=nways;
}
inline void proc() {
    #undef debug
#if defined(debug)
    printf("%d_%s\n",N,str);
#endif
    kmp_autometa(str);
#if defined(debug)
    fo(i,strlen(str)) {
        fo(j,10) {
            printf("%d ",aut[i][j]);
        }
        line;
    }
    line;
#endif
    SET(vis,false);
    int var = go(0,0);
    cout<<var;
    line;
}
int main() {
    int kase=1;
#if !defined ( ONLINE_JUDGE )
    freopen("in","r",stdin);
#endif
    scanf("%d\n",&kase);
    fo(i,kase) {
        read();
        proc();
    }
    return 0;
}


